#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;

#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define out(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define VL vector<ll>
#define VVL vector<VL >
#define VC vector<char>
#define PI pair<int,int>
#define PL pair<ll,ll>
#define EPS 0.0000001


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

//#define INF 5340172838076674L
//#define INF 1000000000
//#define MOD 998244353
//#define W 20

int n,m;
int ch[100005][2];
int f[100005];
int val[100005];
int d[100005];
bool dead[100005];

int &rs(int x){
	return d[ch[x][0]]<d[ch[x][1]]?ch[x][0]:ch[x][1];
}
int merge(int x,int y){
	if(!x||!y)return x|y;
	if(val[x]>val[y])swap(x,y);
	f[rs(x)=merge(rs(x),y)]=x;
	d[x]=d[rs(x)]+1;
	return x;
}

int find(int x){
	if(f[x]==x)return x;
	return f[x]=find(f[x]);
}

int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
	memset(ch,0,sizeof ch);
	memset(d,0,sizeof d);
	memset(dead,0,sizeof dead);
	n=read();m=read();
	for(int i=1;i<=n;i++)val[i]=read();
	for(int i=1;i<=n;i++)f[i]=i;
	int a,b;
	while(m--){
		if(read()==1){
			a=read();b=read();
			if(dead[a]||dead[b])continue;
			merge(find(a),find(b));
		}else{
			a=read();
			if(dead[a]){
				printf("-1\n");
				continue;
			}
			b=find(a);
			dead[b]=1;
			printf("%d\n",val[b]);
			a=merge(ch[b][0],ch[b][1]);
			f[b]=f[a]=a;
		}
	}
}